<?php

namespace App\Admin\Controllers;

use App\Models\Level;
use Dcat\Admin\Form;
use Dcat\Admin\Grid;
use Dcat\Admin\Show;
use Dcat\Admin\Http\Controllers\AdminController;

class LevelController extends AdminController
{
    /**
     * Make a grid builder.
     *
     * @return Grid
     */
    protected function grid()
    {
        return Grid::make(new Level(), function (Grid $grid) {
            $grid->column('id')->sortable();
            $grid->column('name');
            $grid->column('icon')->display(function ($d){
                return "<img src='/{$d}' height='24'>";
            });
            $grid->column('score');
            $grid->column('borrow_num');
            $grid->column('limit_day');
            $grid->column('sort');

            $grid->filter(function (Grid\Filter $filter) {
                $filter->equal('name');

            });

            $grid->showQuickEditButton();
            $grid->disableViewButton();
            $grid->disableEditButton();
        });
    }



    /**
     * Make a form builder.
     *
     * @return Form
     */
    protected function form()
    {
        return Form::make(new Level(), function (Form $form) {
            $form->text('name')->required();
            $form->image('icon')->required()->autoUpload();
            $form->number('score')->default(1)->required();
            $form->number('borrow_num')->default(1)->required();
            $form->number('limit_day')->default(7)->required();
            $form->number('sort')->default(1)->required();
        });
    }
}
